#include "command.h"

int _touch(char *argv[])
{
	/* check the number of cmd-line parameters is correct */
	int argc = 0;
	for (char **ptr = argv; *ptr != NULL; ptr++)
		argc++;

	if (argc < 2) {
		fprintf(stderr, "Usage: touch file1 file2 ... \n");
		return -1;
	}
	
	const char *file;
	int num = 1;
	while ((file = argv[num++]) != NULL) {
		int fd = open(file, O_CREAT, 0644);
		if (fd == -1) {
			fprintf(stderr, "touch error: open\n");
			return -1;
		}
		close(fd);
	}
	return 0;
}
